const Article = require('../../models/article')

module.exports = async (req, res) => {
    // 查询全部信息，分页功能
    let page = req.query.page || 1
    // console.log(req.query);
    let pagesize = 8
    // 查询文章总数
    const count = await Article.countDocuments({})
    // 总页数
    const total = Math.ceil(count / pagesize)
    const start = (page - 1) * pagesize

  Article.find((err, articleDoc) => {
    if (err) {
      return res.status(500).json({
        err_code: 500,
        message: err.message
      })
    }
    // 查询成功判断
    res.status(200).json({
      err_code: 0,
      data: articleDoc,
      pagecount: total,
      count,
      pagesize,
      message: 'success'
    })
  }).limit(pagesize).skip(start)
}